package com.jnu.supermaket;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class InputActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_input);
        Intent intent=getIntent();
         final int position=intent.getIntExtra("position",0);
        final EditText editTextName=findViewById(R.id.edit_text_name) ;
        final EditText editTextPrice=findViewById(R.id.edit_text_price) ;
        String name=intent.getStringExtra("name");
        Double price=intent.getDoubleExtra("price",0);
        if(null!=name){
            editTextName.setText(name);
            editTextPrice.setText(price.toString());
        }

        Button buttonOK=this.findViewById(R.id.OK);
        buttonOK.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View view) {
                Intent intent=new Intent();
                intent.putExtra("position",position);
                intent.putExtra("name",editTextName.getText().toString());
                intent.putExtra("price",Double.parseDouble(editTextPrice.getText().toString()));
                setResult(MainActivity.RESULT_CODE_ADD_DATA,intent);
                InputActivity.this.finish();
            }
        });
    }
}
